© 2013 Torsten Manz mail_logo.gif 20x14

Programs

PRGM mode

Writing Programs

To write a program on the HP-15C you must switch to PRGM mode. To enter PRGM mode click g P/R or press F9 on the keyboard. The display will change and the word "PRGM" appears in the bottom right corner of the display:

prgm_step_000.gif 310x70

You can now start to key in operations, as you would do in Run mode. The HP-15C will record the keys as you type them in but does not execute any function. HP-15C programs are more like macros than like `real´ programs.

Each program must begin with a label; valid labels are the letters "A" to "E" and the numbers "0" to "9" and ".0" to ".9". As an example, we will write a program that starts with label "A". Click f LBL A or key in F8 Q. This is the first program step and it is displayed like this:

prgm_step_001.gif 310x70

Each key on the HP-15C is identified by a two-digit code that is derived from its position on the keypad. The first digit gives the row (starting at 1) and the second digit gives the column (where 0 means 10). For example, LBL is on the first key in the second row and therefore has the key code "21". Digit keys differ from that rule; the (single) digit itself identifies them.

The codes in a three-key sequence are separated by a digit separator. Codes in a two-key sequence are separated by blanks. There are also some four-key sequences like STO + . 5, which adds the contents of the X register to register 15. This sequence is displayed like this:

prgm_step_021.gif 310x70

To complete the program key in the following sequence:

2 × 9 . 8 ÷ √x̅ g RTN

This little program computes the time it takes for an object to fall from a given height to the ground in the earth gravity field. The gravitational acceleration is approximated with 9.8 m/s2.

In PRGM mode you can right-click the display to display the program pop-up menu. The full description of this pop-up menu can be found in the Pop-up Menu section.

prgm_mnemonics_col.gif 164x204

To run the program you must switch back to Run mode. Press g P/R again.

Running a Program

To run a program you press the GSB key followed by the program label. Thus, GSB A will run the program from the previous chapter. While a program is running, the display flashes "running":

prgm_step_run.gif 310x70

On the Simulator programs with an alpha label can also be run by clicking on the labels A through E. Programs with numeric labels can only be run using the GSB key. In addition to that, the Simulator provides several shortcuts to run programs. See the Program (Run mode) section in the keyboard chapter for a complete list.

Any keystroke and any mouse click interrupts a running program.

The GTO key can not be used to run a program. In Run mode GTO A positions the program pointer on the step with label "A", but does not run the program.

◀ PRGM Mode ▲ Top

Program Documentation

With the simulator you can add documention to your programs; a feature not available on the real HP-15C. The documentation has no impact on the program itself. Documented programs are fully compatible with the real HP-15C.

The Description Dialogue

To document a program press F12 or select "Program description…" from the ON pop-up menu to open the program description dialogue box. The dialogue has the following elements:

The elements in the dialogue box (labels, data storage registers and flags) are displayed in

Documentation Life Cycle

When you start to document a program, the documentation is only in the memory of the simulator. To include it in the program, you must save the program file. This is also true for changes to the documentation: You always have to save the program manually. If you open a documented program file, the documentation is copied to the memory of the Simulator. Any existing documentation is overwritten.

When you delete a label or a flag or if you do not use a data storage register any more, it's description is not deleted until you close the Simulator or save the program file. In this cases the documentation is purged, i.e. unused descriptions are deleted and not saved.

If you reuse a previously deleted element prior to closing the Simulator or saving the program, the program description dialogue shows the previous description of that element.

The "Usage" field is a free text field and you can add any text you like, but you should be aware of the following behaviour:

Program Help Files

The program code together with the documentation can be exported to an HTML-file. Open the "Save program…" dialogue box and choose "HTML Files (*.htm, *.html)" from the file type listbox.

Mac OS X: Current releases of Tcl/Tk don't call the save dialogue box with an activated file type listbox. To force the HTML export, add ".htm" to the filename.

If one or all of the following elements are empty, you will be asked if you want to save the file anyway:

The warning message can be disabled in the Preferences dialogue.

If you press CtrlF1 or ShiftF1 on the Simulator, it searches the directory from where you last loaded a program for an HTML-file with the same name as the program file but the extension ".htm" or ".html". If a program help file is found, it is displayed in the help file browser.

All programs in the "progs" directory of this distribution come with a help file. HTML exports can not be reloaded into the Simulator!

◀ Documentation ▲ Top

Program Files

Saving and Opening Programs

The current program is always part of the memory file and is therefore saved automatically every time you save the memory. Moreover, programs can also be saved separately: If you press CtrlS, the operating systems "Save file" dialogue box opens. The Simulator supports the file extensions ".15c" and ".txt"; the default is ".15c".

To open a program file press CtrlO. The operating systems "Open file" dialogue box opens. If a program is read in, all currently loaded programs are deleted. If the new program is larger than the available memory, the display shows "Error 4" and the program is not loaded. There is no option to merge programs upon reading. See the next section on the file format how to do this manually.

The Simulator remembers the last directory used, used for writing or reading a program file. This directory is used as the initial directory the next time you open a dialogue box.

Program File Format

Simulator program files are simple text files. The following figure shows the program file for the little program used in the previous sections:

HP-15C simulator program

 # --------------------------------------------
 # HEWLETT·PACKARD 15C Simulator program
 # Created with version 3.0.00
 # --------------------------------------------

    000 {             }
    001 {    42 21 11 } f LBL A
    002 {           2 } 2
    003 {          20 } ×
    004 {           9 } 9
    005 {          48 } .
    006 {           8 } 8
    007 {          10 } ÷
    008 {          11 } √x̅
    009 {       43 32 } g RTN

 # --------------------------------------------
        

Like on the real HP-15C step "000" is always empty.

Each line in a program file must be of one of the following types:

Program files are encoded in UNICODE by default to preserve all special characters used in mnemonics. You can change the encoding to ASCII (see Preferences), but then mnemonics with special characters are not stored correctly. Key sequences are not affected because key codes contain only digits.
If a file is read in, only the key sequences are used. Line numbers and mnemonics are saved for documentation purposes only.

The Simulator uses the file format described so far, when it writes a program file. Since the files are simple text files, you can use any text editor that supports UNICODE to edit them. When you edit files the only thing you need to take care of are the key sequences. For example, you may want to increase the gravitational acceleration precision in the program example from 9.8 m/s2 to 9.81 m/s2. You just have to insert a new program step with the key code for digit 1 after line "006":

HP-15C simulator program

    ...
    003 {          20 } ×  
    004 {           9 } 9
    005 {          48 } .
    006 {           8 } 8
                  { 1 }
    007 {          10 } ÷
    ...
      

Neither the line number nor the mnemonic must to be specified. Program steps are automatically renumbered when the file is read in. When you write back the program with the Simulator, the full file format will be used. Missing information, like the mnemonics, are added by the Simulator.

Omitting all optional information brings us to the simplest form of the example program file

Simplified file format

 {42 21 11}  
 {2}
 {20}
 {9}
 {48}
 {8}
 {10}
 {11}
 {43 32}
       

◀ Program Files ▲ Top

Menus ▶